package com.huidao.servlet.seller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.huidao.entity.User;
import com.huidao.service.UserService;
import com.huidao.service.UserServiceImpl;

/**
 * Servlet implementation class SellerUpdateServlet
 */
public class SellerUpdateServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SellerUpdateServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		User user = new User();
		user.setUserPassword(request.getParameter("npassword"));
		user.setUserNickname(request.getParameter("nickname"));
		user.setUserTruename(request.getParameter("truename"));
		user.setUserIdnumber(request.getParameter("idnumber"));
		user.setUserPhone(Long.parseLong(request.getParameter("phone")));
		user.setUserShopname(request.getParameter("shopname"));
		String opassword = request.getParameter("opassword");
		//登录之后存储的个人信息
		User sUser = (User) request.getSession().getAttribute("user");
		
		UserService bo = new UserServiceImpl();
		
		int state = bo.update(user, opassword, sUser);
		
		if(state==1){
			//跳转到商家的主页
			response.sendRedirect("SellerGoodsListServlet");
		}else if(state==0){
			response.getWriter().print("您输入的旧密码不正确");
		}else if(state==2){
			response.getWriter().print("修改失败");
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
